package com.api.user.getcontacts;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.test.context.ContextConfiguration;
import org.testng.Assert;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;

import com.api.test.AbstractApiTest;
import com.zyncro.api.IUserApiService;
import com.zyncro.api.exceptions.ZyncroApiException;
import com.zyncro.api.model.PagedItemsResultApi;
import com.zyncro.api.model.UserApi;
import com.zyncro.api.model.UserFilterApiType;

@ContextConfiguration(locations = { "classpath:/user/user-context.xml" })
public class GetContacts extends AbstractApiTest {

	@Value("#{org_users[mainAdmin].appId}")
	private String userId;

	@Value("#{org_users[mainAdmin].password}")
	private String userPassword;

	@Value("#{org_users.totalContactsAll}")
	private int totalContactsAll;

	@Value("#{org_users.totalContactsOrganization}")
	private int totalContactsOrganization;

	@Value("#{org_users.totalContactsExternal}")
	private int totalContactsExternal;

	@BeforeClass
	public void setUpVariables() {

		getApi().login(userId, userPassword);
	}

	@Test
	public void testGetContactsAll() throws ZyncroApiException {

		int pageNumber = 0;
		int itemsPerPage = 0;
		UserFilterApiType userFilterType = UserFilterApiType.ALL_CONTACTS;

		PagedItemsResultApi<UserApi> result = getApi().getService(IUserApiService.class).getContacts(pageNumber, itemsPerPage, userFilterType);

		Assert.assertEquals(result.getTotalItems(), totalContactsAll);
	}

	@Test
	public void testGetContactsOrganization() throws ZyncroApiException {

		int pageNumber = 0;
		int itemsPerPage = 0;
		UserFilterApiType userFilterType = UserFilterApiType.ONLY_ORGANIZATION_CONTACTS;

		PagedItemsResultApi<UserApi> result = getApi().getService(IUserApiService.class).getContacts(pageNumber, itemsPerPage, userFilterType);

		Assert.assertEquals(result.getTotalItems(), totalContactsOrganization);
	}

	@Test
	public void testGetContactsExternal() throws ZyncroApiException {

		int pageNumber = 0;
		int itemsPerPage = 0;
		UserFilterApiType userFilterType = UserFilterApiType.ONLY_EXTERNAL_CONTACTS;

		PagedItemsResultApi<UserApi> result = getApi().getService(IUserApiService.class).getContacts(pageNumber, itemsPerPage, userFilterType);

		Assert.assertEquals(result.getTotalItems(), totalContactsExternal);
	}
}
